package Singleton;

// 最方便的饿汉式单例，仍然放止不了unsafe类
public enum  Singleton2 {
    INSTANCE1,INSTANCE2;  // 若有2个INSTANCE，私有构造会在使用枚举之前调用2次
    private Singleton2() {  // 枚举类默认 private
        System.out.println("private Singleton2()");
    }

    @Override
    public String toString() {
        return getClass().getName()+"@"+Integer.toHexString(hashCode());
    }

    // INSTANCE默认是public 实际不用写getInstance
    public static Singleton2 getInstance(){
        return INSTANCE1;
    }

    public static void otherMethod(){
        System.out.println("Singleton2 otherMethod");
    }
}
